#!/bin/sh
#
# Sentinel - IRC Statistical and Operator Services
# geninfo.sh - Generates info.c, variables needed from the external
#              environment.
#
# Copyright W. Campbell and others.  See README for more details
# Some code Copyright: Jonathan George, Kai Seidler, ircd-hybrid Team,
#                      IRCnet IRCD developers.
#
# $Id$

# If you create a patch for the service, add it's patch item to this
# variable.
patches=""

if test -r info.c.last
then
   generation=`sed -n 's/^char \*generation = \"\(.*\)\";/\1/p' < info.c.last`
   if test ! "$generation" ; then generation=0; fi
else
   generation=0
fi

generation=`expr $generation + 1`

creation=`date | \
awk '{if (NF == 6) \
         { print $1 " "  $2 " " $3 " "  $6 " at " $4 " " $5 } \
else \
         { print $1 " "  $2 " " $3 " " $7 " at " $4 " " $5 " " $6 }}'`

echo "Generating info.c..."

cat > info.c <<INFO!ENDL
/* Sentinel - info.c - Automatically generated server information
**                     for inclusion in the m_info() function
*/

char *generation = "$generation";

const char *infotext[] = 
{
	"",
INFO!ENDL

patchlevel=`grep 'define PATCHLEVEL' ../include/patchlevel.h | awk '{print $3;}' | tr -d '\"' | tr -d '\r' | tr -d '\n' | sed -e 's/^  *//'`
serial=`grep SERIALNUM ../include/serno.h | awk '{print $3;}' | tr -d '\"'`

echo "	\"$patchlevel($serial)\"," >> info.c
echo "	\"\"," >> info.c

IFS='
'
for i in `grep -h '$Id' ../include/*.h *.c | tr -d '*' | tr -d '\"'`; do
i=`echo $i | sed -e 's/^  *//'`
# i=`echo $i | sed -e 's/ +$//'`
echo "	\"$i\"," >> info.c
done

cat >> info.c <<INFO!ENDL
	"",
        "Compiled on `uname -sr`",
	"on $creation",
	"generation #$generation",
	0
};

char *stats_version = "${patchlevel}${patches}(${serial}).";
char *stats_date = "$creation";

INFO!ENDL
